#include <iostream>
#include <cv.h>
#include <highgui.h>

using namespace std;
using namespace cv;

int main(int argc, char* argv[]) {
    Mat image;
    Mat outline;

    image = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
    threshold(image, image, 200, 255, THRESH_BINARY);

    int ink = countNonZero(image);

//    cout << ink << endl;

    dilate(image, outline, Mat());

    outline = outline - image;

    dilate(outline, outline, Mat());

    int perimeter = countNonZero(outline) / 3;

//    cout << perimeter << endl;

    cout << (float)perimeter * perimeter / ink << endl;

    /*
    namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
    imshow("Display Image", outline);

    waitKey(0);
    */

    return 0;
}

float complexity(Mat src) {
    Mat outline;
    int ink = countNonZero(src);
    dilate(src, outline, Mat());
    outline = outline - src;
    dilate(outline, outline, Mat());
    int perimeter = countNonZero(outline) / 3;
    return 1.0 / ((float)perimeter*perimeter / ink);
}
